﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace hcrainMvc.DAL
{
	/// <summary>
	/// 数据访问类:hcr_w_next
	/// </summary>
	public partial class hcr_w_next
	{
		public hcr_w_next()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(long id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from hcr_w_next");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(hcrainMvc.Model.hcr_w_next model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into hcr_w_next(");
			strSql.Append("fdeid,fnname,fntype,fnextid,fnextname,fntypeauto,fstatefyw,fnautofiles,fback,fbackvalue,fnextsel,fnextselvalue,fnextusersel,fnextuserselvalue,fcanstop,fdodep,fdoorg,fdouser,fdourl,fcansave,fdotitle,fcandel,fdoonlyuser)");
			strSql.Append(" values (");
			strSql.Append("@fdeid,@fnname,@fntype,@fnextid,@fnextname,@fntypeauto,@fstatefyw,@fnautofiles,@fback,@fbackvalue,@fnextsel,@fnextselvalue,@fnextusersel,@fnextuserselvalue,@fcanstop,@fdodep,@fdoorg,@fdouser,@fdourl,@fcansave,@fdotitle,@fcandel,@fdoonlyuser)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@fdeid", MySqlDbType.VarChar,100),
					new MySqlParameter("@fnname", MySqlDbType.VarChar,50),
					new MySqlParameter("@fntype", MySqlDbType.VarChar,50),
					new MySqlParameter("@fnextid", MySqlDbType.VarChar,100),
					new MySqlParameter("@fnextname", MySqlDbType.VarChar,100),
					new MySqlParameter("@fntypeauto", MySqlDbType.VarChar,500),
					new MySqlParameter("@fstatefyw", MySqlDbType.VarChar,100),
					new MySqlParameter("@fnautofiles", MySqlDbType.VarChar,500),
					new MySqlParameter("@fback", MySqlDbType.VarChar,11),
					new MySqlParameter("@fbackvalue", MySqlDbType.VarChar,10),
					new MySqlParameter("@fnextsel", MySqlDbType.VarChar,11),
					new MySqlParameter("@fnextselvalue", MySqlDbType.VarChar,100),
					new MySqlParameter("@fnextusersel", MySqlDbType.VarChar,11),
					new MySqlParameter("@fnextuserselvalue", MySqlDbType.VarChar,100),
					new MySqlParameter("@fcanstop", MySqlDbType.VarChar,11),
					new MySqlParameter("@fdodep", MySqlDbType.VarChar,100),
					new MySqlParameter("@fdoorg", MySqlDbType.VarChar,100),
					new MySqlParameter("@fdouser", MySqlDbType.VarChar,100),
					new MySqlParameter("@fdourl", MySqlDbType.VarChar,100),
					new MySqlParameter("@fcansave", MySqlDbType.VarChar,100),
					new MySqlParameter("@fdotitle", MySqlDbType.VarChar,100),
					new MySqlParameter("@fcandel", MySqlDbType.VarChar,200),
					new MySqlParameter("@fdoonlyuser", MySqlDbType.VarChar,200)};
			parameters[0].Value = model.fdeid;
			parameters[1].Value = model.fnname;
			parameters[2].Value = model.fntype;
			parameters[3].Value = model.fnextid;
			parameters[4].Value = model.fnextname;
			parameters[5].Value = model.fntypeauto;
			parameters[6].Value = model.fstatefyw;
			parameters[7].Value = model.fnautofiles;
			parameters[8].Value = model.fback;
			parameters[9].Value = model.fbackvalue;
			parameters[10].Value = model.fnextsel;
			parameters[11].Value = model.fnextselvalue;
			parameters[12].Value = model.fnextusersel;
			parameters[13].Value = model.fnextuserselvalue;
			parameters[14].Value = model.fcanstop;
			parameters[15].Value = model.fdodep;
			parameters[16].Value = model.fdoorg;
			parameters[17].Value = model.fdouser;
			parameters[18].Value = model.fdourl;
			parameters[19].Value = model.fcansave;
			parameters[20].Value = model.fdotitle;
			parameters[21].Value = model.fcandel;
			parameters[22].Value = model.fdoonlyuser;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(hcrainMvc.Model.hcr_w_next model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update hcr_w_next set ");
			strSql.Append("fdeid=@fdeid,");
			strSql.Append("fnname=@fnname,");
			strSql.Append("fntype=@fntype,");
			strSql.Append("fnextid=@fnextid,");
			strSql.Append("fnextname=@fnextname,");
			strSql.Append("fntypeauto=@fntypeauto,");
			strSql.Append("fstatefyw=@fstatefyw,");
			strSql.Append("fnautofiles=@fnautofiles,");
			strSql.Append("fback=@fback,");
			strSql.Append("fbackvalue=@fbackvalue,");
			strSql.Append("fnextsel=@fnextsel,");
			strSql.Append("fnextselvalue=@fnextselvalue,");
			strSql.Append("fnextusersel=@fnextusersel,");
			strSql.Append("fnextuserselvalue=@fnextuserselvalue,");
			strSql.Append("fcanstop=@fcanstop,");
			strSql.Append("fdodep=@fdodep,");
			strSql.Append("fdoorg=@fdoorg,");
			strSql.Append("fdouser=@fdouser,");
			strSql.Append("fdourl=@fdourl,");
			strSql.Append("fcansave=@fcansave,");
			strSql.Append("fdotitle=@fdotitle,");
			strSql.Append("fcandel=@fcandel,");
			strSql.Append("fdoonlyuser=@fdoonlyuser");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@fdeid", MySqlDbType.VarChar,100),
					new MySqlParameter("@fnname", MySqlDbType.VarChar,50),
					new MySqlParameter("@fntype", MySqlDbType.VarChar,50),
					new MySqlParameter("@fnextid", MySqlDbType.VarChar,100),
					new MySqlParameter("@fnextname", MySqlDbType.VarChar,100),
					new MySqlParameter("@fntypeauto", MySqlDbType.VarChar,500),
					new MySqlParameter("@fstatefyw", MySqlDbType.VarChar,100),
					new MySqlParameter("@fnautofiles", MySqlDbType.VarChar,500),
					new MySqlParameter("@fback", MySqlDbType.VarChar,11),
					new MySqlParameter("@fbackvalue", MySqlDbType.VarChar,10),
					new MySqlParameter("@fnextsel", MySqlDbType.VarChar,11),
					new MySqlParameter("@fnextselvalue", MySqlDbType.VarChar,100),
					new MySqlParameter("@fnextusersel", MySqlDbType.VarChar,11),
					new MySqlParameter("@fnextuserselvalue", MySqlDbType.VarChar,100),
					new MySqlParameter("@fcanstop", MySqlDbType.VarChar,11),
					new MySqlParameter("@fdodep", MySqlDbType.VarChar,100),
					new MySqlParameter("@fdoorg", MySqlDbType.VarChar,100),
					new MySqlParameter("@fdouser", MySqlDbType.VarChar,100),
					new MySqlParameter("@fdourl", MySqlDbType.VarChar,100),
					new MySqlParameter("@fcansave", MySqlDbType.VarChar,100),
					new MySqlParameter("@fdotitle", MySqlDbType.VarChar,100),
					new MySqlParameter("@fcandel", MySqlDbType.VarChar,200),
					new MySqlParameter("@fdoonlyuser", MySqlDbType.VarChar,200),
					new MySqlParameter("@id", MySqlDbType.Int64,20)};
			parameters[0].Value = model.fdeid;
			parameters[1].Value = model.fnname;
			parameters[2].Value = model.fntype;
			parameters[3].Value = model.fnextid;
			parameters[4].Value = model.fnextname;
			parameters[5].Value = model.fntypeauto;
			parameters[6].Value = model.fstatefyw;
			parameters[7].Value = model.fnautofiles;
			parameters[8].Value = model.fback;
			parameters[9].Value = model.fbackvalue;
			parameters[10].Value = model.fnextsel;
			parameters[11].Value = model.fnextselvalue;
			parameters[12].Value = model.fnextusersel;
			parameters[13].Value = model.fnextuserselvalue;
			parameters[14].Value = model.fcanstop;
			parameters[15].Value = model.fdodep;
			parameters[16].Value = model.fdoorg;
			parameters[17].Value = model.fdouser;
			parameters[18].Value = model.fdourl;
			parameters[19].Value = model.fcansave;
			parameters[20].Value = model.fdotitle;
			parameters[21].Value = model.fcandel;
			parameters[22].Value = model.fdoonlyuser;
			parameters[23].Value = model.id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from hcr_w_next ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from hcr_w_next ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.hcr_w_next GetModel(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,fdeid,fnname,fntype,fnextid,fnextname,fntypeauto,fstatefyw,fnautofiles,fback,fbackvalue,fnextsel,fnextselvalue,fnextusersel,fnextuserselvalue,fcanstop,fdodep,fdoorg,fdouser,fdourl,fcansave,fdotitle,fcandel,fdoonlyuser from hcr_w_next ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			hcrainMvc.Model.hcr_w_next model=new hcrainMvc.Model.hcr_w_next();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.hcr_w_next DataRowToModel(DataRow row)
		{
			hcrainMvc.Model.hcr_w_next model=new hcrainMvc.Model.hcr_w_next();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=long.Parse(row["id"].ToString());
				}
				if(row["fdeid"]!=null)
				{
					model.fdeid=row["fdeid"].ToString();
				}
				if(row["fnname"]!=null)
				{
					model.fnname=row["fnname"].ToString();
				}
				if(row["fntype"]!=null)
				{
					model.fntype=row["fntype"].ToString();
				}
				if(row["fnextid"]!=null)
				{
					model.fnextid=row["fnextid"].ToString();
				}
				if(row["fnextname"]!=null)
				{
					model.fnextname=row["fnextname"].ToString();
				}
				if(row["fntypeauto"]!=null)
				{
					model.fntypeauto=row["fntypeauto"].ToString();
				}
				if(row["fstatefyw"]!=null)
				{
					model.fstatefyw=row["fstatefyw"].ToString();
				}
				if(row["fnautofiles"]!=null)
				{
					model.fnautofiles=row["fnautofiles"].ToString();
				}
				if(row["fback"]!=null)
				{
					model.fback=row["fback"].ToString();
				}
				if(row["fbackvalue"]!=null)
				{
					model.fbackvalue=row["fbackvalue"].ToString();
				}
				if(row["fnextsel"]!=null)
				{
					model.fnextsel=row["fnextsel"].ToString();
				}
				if(row["fnextselvalue"]!=null)
				{
					model.fnextselvalue=row["fnextselvalue"].ToString();
				}
				if(row["fnextusersel"]!=null)
				{
					model.fnextusersel=row["fnextusersel"].ToString();
				}
				if(row["fnextuserselvalue"]!=null)
				{
					model.fnextuserselvalue=row["fnextuserselvalue"].ToString();
				}
				if(row["fcanstop"]!=null)
				{
					model.fcanstop=row["fcanstop"].ToString();
				}
				if(row["fdodep"]!=null)
				{
					model.fdodep=row["fdodep"].ToString();
				}
				if(row["fdoorg"]!=null)
				{
					model.fdoorg=row["fdoorg"].ToString();
				}
				if(row["fdouser"]!=null)
				{
					model.fdouser=row["fdouser"].ToString();
				}
				if(row["fdourl"]!=null)
				{
					model.fdourl=row["fdourl"].ToString();
				}
				if(row["fcansave"]!=null)
				{
					model.fcansave=row["fcansave"].ToString();
				}
				if(row["fdotitle"]!=null)
				{
					model.fdotitle=row["fdotitle"].ToString();
				}
				if(row["fcandel"]!=null)
				{
					model.fcandel=row["fcandel"].ToString();
				}
				if(row["fdoonlyuser"]!=null)
				{
					model.fdoonlyuser=row["fdoonlyuser"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,fdeid,fnname,fntype,fnextid,fnextname,fntypeauto,fstatefyw,fnautofiles,fback,fbackvalue,fnextsel,fnextselvalue,fnextusersel,fnextuserselvalue,fcanstop,fdodep,fdoorg,fdouser,fdourl,fcansave,fdotitle,fcandel,fdoonlyuser ");
			strSql.Append(" FROM hcr_w_next ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM hcr_w_next ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from hcr_w_next T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "hcr_w_next";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

